# -*- coding: utf-8 -*-
# @Time    : 2024/10/29 16:27
# @Author  : CHNJX
# @File    : logger.py
# @Desc    :

import logging
from logging.handlers import RotatingFileHandler

def setup_logger(app):
    """配置应用日志"""
    if not app.debug:
        # 创建日志处理器
        file_handler = RotatingFileHandler(
            'logs/app.log',
            maxBytes=10240,
            backupCount=10
        )
        file_handler.setFormatter(logging.Formatter(
            '%(asctime)s %(levelname)s: %(message)s '
            '[in %(pathname)s:%(lineno)d]'
        ))
        file_handler.setLevel(logging.INFO)
        app.logger.addHandler(file_handler)

    app.logger.setLevel(logging.INFO)
